﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Roton.ZZT
{
    partial class Context
    {
        int boardLimit;
        int textElementStart;
        int thingLimit;

        public void Attack(int index, int targetX, int targetY)
        {

        }

        public IThing GetThingAt(int x, int y)
        {
            return memory.GetThing(GetThingIndexAt(x, y));
        }

        public int GetThingIndexAt(int x, int y)
        {
            return -1;
        }

        public void HarmThing(int index)
        {
        }

        public void MoveThing(int index, int targetX, int targetY)
        {

        }

        public int PosNeg(int i)
        {
            if (i > 0)
                return 1;
            else if (i < 0)
                return -1;
            else
                return 0;
        }

        public void RemoveThing(int index)
        {

        }

        public void SetVectorRandom(IVector v)
        {
            v.X = Random(3) - 1;
            if (v.X == 0)
                v.Y = (Random(2) << 1) - 1;
            else
                v.Y = 0;
        }

        public void SetVectorSeek(int x, int y, IVector v)
        {
            IThing player = memory.GetThing(0);

            v.X = 0;
            v.Y = 0;

            if (Random(2) == 0 || player.Y == y)
                v.X = PosNeg(player.X - x);
            if (v.X == 0)
                v.Y = PosNeg(player.Y - y);

            if (memory.World.EnergyCycles > 0)
            {
                v.X = -v.X;
                v.Y = -v.Y;
            }
        }

        public bool SpawnProjectile(int element, int shooterX, int shooterY, int vectorX, int vectorY, bool enemyOwned)
        {
            return false;
        }

        public void SpawnThing(int x, int y, int element, int color, int cycle, IThing template)
        {
            IState state = memory.State;
            IThing thing;

            if (state.ThingCount < parameters.ThingLimit)
            {
                state.ThingCount++;
                thing = memory.GetThing(state.ThingCount);
                thing.X = x;
                thing.Y = y;
                thing.StepX = template.StepX;
                thing.StepY = template.StepY;
                thing.Cycle = cycle;
                thing.P1 = template.P1;
                thing.P2 = template.P2;
                thing.P3 = template.P3;
                thing.Follower = template.Follower;
                thing.Leader = template.Leader;
                thing.UnderID = GetIDAt(x, y);
                thing.UnderColor = GetColorAt(x, y);
                thing.Instruction = 0;
            }
        }
    }
}
